<?php include_once '../../../../include/inc_session.php';	

	$idContrat = isset($_POST['Identifiant_contrat'])? $_POST['Identifiant_contrat']: $_GET['idcontrat'];
	$idRefExt = isset($_POST['idrefext'])? $_POST['idrefext'] : $_GET['idrefext'];
	
	$oContrat = new dataObject_contrat($idContrat);
	$oProduit = new dataObject_produit();
	$oRefExt = new dataObject_refExterne($idRefExt);
	
	$aList = $oProduit->produit_getListGarantieOptionnelle($_SESSION['produit']);
	
	$TYPE    =  (isset($_POST['Type_refexterne']))  ?  $_POST['Type_refexterne']  : $oRefExt->_TYPE_REFEXT;
	$VALEUR    =  (isset($_POST['ORE_Valeur_refexterne'])) ?  $_POST['ORE_Valeur_refexterne'] : $oRefExt->_VALEUR_REFEXT;
	
	
	$nommodule2="Détail référence externe";

	if ($gbFormValid) 
	{
		$oRefExt->_TYPE_REFEXT 			= $TYPE;
		$oRefExt->_VALEUR_REFEXT 			= $VALEUR;
		$oRefExt->_IDENTIFIANT_CONTRAT 	= $idContrat;
		
		if($idRefExt != '')
		{			
			$id = $oRefExt->refExterne_update();
			if($id=== false) $oForm->ajouterErreur(chgmt_couv_mod_refext_pbm);
			else $oForm->ajouterErreur(refexterne_modif);
		}
		else
		{
			$id = $oRefExt->refExterne_insert();
			if(!$id) $oForm->ajouterErreur(chgmt_couv_crea_refext_pbm);
			else $oForm->ajouterErreur(refexterne_creation);
		}
		
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reference externe</title>
<link rel="stylesheet" type="text/css" href="../../../../css/main.css" />
<link rel="stylesheet" type="text/css" href="list.css" />

</head>
<body>
<div id="sf_menu1">
	<h3><?php echo $oBloc->_MENU_NOM ?></h3>
	<div id="information_erreur" class="false">
        <ul id="message">
        	<li><?php $aMsg =$oForm->getValidMessage(); echo (!empty($aMsg))? $aMsg[0]['message'] : ''; ?></li>
        </ul>
    </div>
    
</div>


<div class="corps1">
<div class="cleared"></div>
<div id="br"></div>
<!--/***************************************/-->
<form action="<?php echo $sEditFormAction; ?>" method="post" name="form2" id="form2">
	<div class="imgleft"></div>
	<div class="imgmiddle">
		<div class="btn">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $oFonction->_MENU_AFFICHE; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="btn1">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $nommodule2; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="cleared"></div>
	<div class="formulaire">
  <table class="tabform">
    <tr>
      <td class="td0">TYPE REFERENCE</td>
      <td><select name="Type_refexterne">
		<?php 
		$aTypeList = dataObject_elementdico::elementdico_getListFromCode(dataObject_dictionnaire::_TYPE_REF_EXTERNE);
		foreach ($aTypeList as $i => $aRow)
		{ ?>
			<option value="<?php echo $aRow['Code_element']; ?>" <?php echo remind_select('Type_refexterne', $aRow['Code_element']); echo remind_select2($TYPE, $aRow['Code_element']);  ?> ><?php echo $aRow['Nom_element']; ?></option>
		<?php 
		} 
		 ?>
      </select>
      </td>
    </tr>
	
    <tr>
      <td class="td0">VALEUR</td>
      <td><input type="text" name="ORE_Valeur_refexterne" value="<?php if(isset($_POST['ORE_Valeur_refexterne'])){ echo remind_text('ORE_Valeur_refexterne'); }else{ echo htmlentities($oRefExt->_VALEUR_REFEXT, ENT_COMPAT, 'utf-8');} ?>" size="32" maxlength="30" /></td>
    </tr>
	
  </table>
    
    </div>
    
 </div>


<div class="imgright"></div>
<?php
		$sUrlRetour = "index.php?idcontrat=".$idContrat;
?>
    				
    <div class="bt1"> <a href="<?php echo $sUrlRetour;?>"><span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a></div>
    
     
    
      <div class="bt1">
	<span class="btleft"></span><input type="submit" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span></div>
    
	
      
  
   <div class="cleared"></div>

  <input type="hidden" name="Identifiant_contrat" value="<?php echo $idContrat; ?>" />
  <input type="hidden" name="idrefext" value="<?php echo $idRefExt; ?>" />
  <input type="hidden" name="MM_insert" value="form1" />
</form> </div>
</body>
</html>
<?php
include_once PATH_INCLUDE.'inc_pied_page.php';

?>